home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume16 / deliver / part01 next >
Encoding:
Internet Message Format  |  1988-11-14  |  29.5 KB

  1. Subject:  v16i081:  Mail delivery program, Part01/03
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4.  
  5. Submitted-by: Chip Salzenberg <ateng!chip@uunet.uu.net>
  6. Posting-number: Volume 16, Issue 81
  7. Archive-name: deliver/part01
  8.  
  9. A long time ago, I wanted to set up a mail alias that could pipe mail
  10. through a process.  Well, one thing led to another, and the result is
  11. this program:  deliver.
  12.  
  13. Deliver does mail delivery.  It is, however, unique in that its
  14. configuration files are shell scripts.  Thus a user is not limited to simply
  15. piping his mail; he can do anything that he can express in a shell script.
  16. One beta tester, for example, bounces daytime mail to his work machine
  17. and night/weekend mail to his home machine.
  18.  
  19. This program has been tested under Xenix System V and 4.3 BSD.  It should
  20. work under System V with minimal work.
  21. --
  22. Chip Salzenberg                   <chip@ateng.uu.net> or <uunet!ateng!chip>
  23. A T Engineering                      stuck in a closet with Vanna White
  24. --
  25. #! /bin/sh
  26. # This is a shell archive.  Remove anything before this line, then unpack
  27. # it by saving it into a file and typing "sh file".  To overwrite existing
  28. # files, type "sh file -c".  You can also feed this as standard input via
  29. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  30. # will see the following message at the end:
  31. #        "End of shell archive."
  32. # Contents:  README deliver.8 Makefile config.h context.h deliver.h
  33. #   dest.h patchlevel.h misc.h
  34. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  35. if test -f 'README' -a "${1}" != "-c" ; then 
  36.   echo shar: Will not clobber existing file \"'README'\"
  37. else
  38. echo shar: Extracting \"'README'\" \(2335 characters\)
  39. sed "s/^X//" >'README' <<'END_OF_FILE'
  40. X$Header: README,v 1.5 88/09/14 20:09:37 network Exp $
  41. X
  42. X
  43. X                             WHAT IS DELIVER?
  44. X
  45. X
  46. XDeliver is a program which delivers electronic mail once it has arrived
  47. Xat a given machine.
  48. X
  49. X
  50. X
  51. X                              WHO CAN USE IT?
  52. X
  53. X
  54. XDeliver is intended for use in three environments:
  55. X
  56. X
  57. X    1.  Any Xenix system.
  58. X
  59. X        Deliver was invented to be a direct replacement for the Xenix
  60. X        program /usr/lib/mail/mail.local.  In fact, on ateng, mail.local is
  61. X    just another link to /usr/bin/deliver.
  62. X
  63. X
  64. X    2.  Any Unix system with smail 2.x.
  65. X
  66. X        You can use deliver for local mail by changing the local mailer
  67. X        definition in config.h:
  68. X        #define LMAIL(frm)      "/usr/bin/deliver -r '%s'",frm
  69. X
  70. X
  71. X    3.  Any Unix system with either sendmail or smail 3.x.
  72. X
  73. X    Any user can let deliver handle all his mail by putting the
  74. X    following line in his .forward file:
  75. X        "|/usr/bin/deliver username"
  76. X    Be sure to specify the correct username, or someone else will
  77. X    get your mail!
  78. X
  79. X
  80. X
  81. X                                PORTABILITY
  82. X
  83. X
  84. XDeliver has been compiled and tested under SCO Xenix System V/286 and 4.3
  85. XBSD.  The configuration provides for System V, but I have not been able to
  86. Xtest it. (Patches for all environments are welcome; see below.)
  87. X
  88. X
  89. X
  90. X               WARNINGS: BE CAREFUL!
  91. X
  92. X
  93. X    1.  Deliver is intended to be run setuid root; otherwise it would not
  94. X        be possible to execute a user delivery file in the context of its
  95. X        owner.  Any setuid root program is a potential security hole!  Be
  96. X        careful of the modes on the deliver binary and the directory where
  97. X        it lives.
  98. X
  99. X    2.  Deliver's flexibility makes it easy to lose lots of mail through
  100. X    carelessness in configuration.  Delivery files should be written
  101. X    with extreme care.
  102. X
  103. X
  104. X
  105. X                          COMPILING AND INSTALLING
  106. X
  107. X
  108. XEdit the Makefile and config.h to taste.  Type "make".  To install, type
  109. X"make install".  See the Makefile for further hints.
  110. X
  111. X
  112. X
  113. X                HELP SAVE THE WORLD!
  114. X
  115. X
  116. XIf you run into a bug, you are probably not alone.  Save your fellow human
  117. Xbeings from toil and trouble!  Send mail to <bugs-deliver@ateng.uucp>.  Bug
  118. Xreports accepted; patches greatly appreciated.  I will coordinate patches.
  119. X
  120. XThank you, and good night.
  121. X
  122. X    Chip Salzenberg
  123. X    A T Engineering
  124. X
  125. X    <chip@ateng.uucp> or
  126. X    <chip@ateng.uu.net> or
  127. X    <uunet!ateng!chip>
  128. END_OF_FILE
  129. if test 2335 -ne `wc -c <'README'`; then
  130.     echo shar: \"'README'\" unpacked with wrong size!
  131. fi
  132. # end of 'README'
  133. fi
  134. if test -f 'deliver.8' -a "${1}" != "-c" ; then 
  135.   echo shar: Will not clobber existing file \"'deliver.8'\"
  136. else
  137. echo shar: Extracting \"'deliver.8'\" \(8688 characters\)
  138. sed "s/^X//" >'deliver.8' <<'END_OF_FILE'
  139. X.\" $Header: deliver.8,v 1.3 88/09/14 19:41:44 network Exp $
  140. X.\"
  141. X.\" Man page for deliver.
  142. X.\"
  143. X.\" $Log:    deliver.8,v $
  144. X.\" Revision 1.3  88/09/14  19:41:44  network
  145. X.\" Portability to System V and BSD.
  146. X.\" General fixup.
  147. X.\" 
  148. X.\" Revision 1.2  88/08/25  14:58:31  network
  149. X.\" Document -u and -s.  Also general cleanup.
  150. X.\" Change default system delivery file.
  151. X.\" 
  152. X.\" Revision 1.1  88/06/06  09:33:50  chip
  153. X.\" Initial revision
  154. X.\" 
  155. X.\"
  156. X.TH DELIVER 8
  157. X.SH NAME
  158. Xdeliver \- deliver local mail
  159. X.SH SYNOPSIS
  160. X.B deliver
  161. X[ options ] address ...
  162. X.SH DESCRIPTION
  163. XThe
  164. X.I deliver
  165. Xprogram collects a mail message from the standard input and delivers it.
  166. XIt is intended to take over the delivery of all local mail, a job which
  167. Xis usually handled by
  168. X.I /bin/mail
  169. X(that's
  170. X.I /usr/lib/mail/mail.local
  171. Xon Xenix systems).
  172. X.PP
  173. XA mail system which uses
  174. X.I deliver
  175. Xbecomes very flexible in its handling of local mail delivery.  All files
  176. Xused to control
  177. X.I deliver
  178. Xare shell scripts.  Thus anything you can express in a shell script can
  179. Xbe used to control mail delivery.
  180. X.PP
  181. X.I deliver
  182. Xwas designed for use in two environments.  If your Unix system uses
  183. X.I smail(8)
  184. Xto handle incoming mail, then you can change the LMAIL macro to call
  185. X.I deliver.
  186. XOr, if you have a Xenix system,
  187. X.I deliver
  188. Xcan be used as a direct replacement for
  189. X.IR /usr/lib/mail/mail.local.
  190. X(If you are using
  191. X.I smail
  192. Xunder Xenix, either of these approaches will work.)
  193. X.I deliver
  194. Xcan also be used with
  195. X.I sendmail
  196. Xor
  197. X.I smail
  198. Xversion 3, through the use of
  199. X.I .forward
  200. Xfiles.
  201. X.PP
  202. XBy default,
  203. X.I deliver
  204. Xdeposits mail in the system mailbox for the named user(s).  However,
  205. X.I deliver
  206. Xis useful specifically because of its ability to vary its behavior
  207. Xdepending on the recipient(s) and content of mail messages.
  208. X.PP
  209. XWhen
  210. X.I deliver
  211. Xstarts execution, it interprets its arguments in one of three ways.  If the
  212. X.B \-b
  213. X(mailbox) option was specified, then all arguments are interpreted as
  214. Xmailbox pathnames.  Otherwise, if a system delivery file exists,
  215. X.I deliver
  216. Xexecutes it with all of deliver's arguments, interpreting the output as
  217. Xdescribed below; this procedure gives the postmaster control over delivery
  218. Xto non-existent user names.  If
  219. X.I deliver
  220. Xcannot find a system delivery file, it interprets all its arguments as
  221. Xuser names.
  222. X.PP
  223. XAfter executing the system delivery file (if any),
  224. X.I deliver
  225. Xlooks in its list of destinations for valid user names without explicitly
  226. Xnamed mailboxes.  If any of those users have user delivery files in their
  227. Xhome directories,
  228. X.I deliver
  229. Xexecutes each delivery file with the name of the user for its only argument.
  230. X.bp
  231. X.SH OPTIONS
  232. X.TP
  233. X.B \-b
  234. XInterpret all arguments as mailboxes instead of addresses.
  235. X.TP
  236. X.B \-A
  237. XPrint the resolved addresses; don't deliver to any mailboxes.  Note that
  238. X.I deliver
  239. Xstill collects a message from the standard input, since delivery files may
  240. Xdo different things depending on message content.  For simple testing,
  241. Xredirect standard input from /dev/null.
  242. X.TP
  243. X.B \-d
  244. XBe verbose; don't deliver to any mailboxes or catch any signals.
  245. X.TP
  246. X.B \-v
  247. XBe verbose, but still deliver.
  248. X.TP
  249. X.B \-t
  250. XDo not remove temporary files before exiting.
  251. X.TP
  252. X.BI \-r " sender"
  253. XPut
  254. X.I sender
  255. Xon the generated From_ line.  Default is to use the address on the From_
  256. Xline in the input, or else the name corresponding to the real uid, or else
  257. X"unknown".
  258. X.TP
  259. X.BI \-h " hostname"
  260. XSet the host name.  The default is configuration dependent.
  261. X.TP
  262. X.BI \-s " system delivery file"
  263. XSpecify an alternate system delivery file.  The default is
  264. X.I /usr/local/lib/deliver.sys.
  265. XFor security reasons, this option disables setuid privileges.
  266. X.TP
  267. X.BI \-u " user delivery file"
  268. XSpecify an alternate user delivery file.  The default is
  269. X.I .deliver
  270. X(in each user's home directory).
  271. XFor security reasons, this option disables setuid privileges.
  272. X.PP
  273. XAll command line options are put into environment variables, which
  274. X.I deliver
  275. Xexamines on startup; thus all flags are propagated when
  276. X.I deliver
  277. Xis invoked recursively.
  278. X.bp
  279. X.SH DELIVERY FILES
  280. XDelivery files are shell scripts.  They are executed by
  281. X.I deliver
  282. Xto control delivery to users.  Note that delivery files do
  283. X.I not
  284. Xcontrol delivery to explicitly named mailboxes.
  285. X.PP
  286. XOn each system the postmaster may create a
  287. X.I system delivery file
  288. Xto controls delivery of all messages.
  289. XThe system delivery file, if it exists, is executed
  290. Xwith the name(s) specified on the
  291. X.I deliver
  292. Xcommand line as its arguments.
  293. X.PP
  294. XIn addition, each user may create a
  295. X.I user delivery file
  296. Xin his home directory.  User delivery files are always executed with exactly
  297. Xone argument: the name of the user in whose home directory the file is
  298. Xfound.
  299. X.PP
  300. XWhen
  301. X.I deliver
  302. Xexecutes a delivery file, it sets several environment variables, listed
  303. Xbelow.
  304. XNote that these environment variables are both set and used by
  305. X.I deliver;
  306. Xtherefore, all command line options automatically propagate when
  307. X.I deliver
  308. Xis run recursively (within a delivery file).  Recursive execution of
  309. X.I deliver
  310. Xis quite useful, especially with the
  311. X.B \-b
  312. X(mailbox) flag.
  313. X.TP
  314. X.B DELFLAGS
  315. XThe command line flags, if any, specified on the
  316. X.I deliver
  317. Xcommand line.
  318. X.TP
  319. X.B SYSDELFILE
  320. XThe system delivery filename.
  321. X.TP
  322. X.B USERDELFILE
  323. XThe user delivery filename.
  324. X.TP
  325. X.B HOSTNAME
  326. XThe local host name, either the actual hostname or a name specified with the
  327. X.B \-h
  328. Xoption to
  329. X.I deliver.
  330. X.TP
  331. X.B SENDER
  332. XThe sender, if any, specified with the
  333. X.B \-r
  334. Xoption to
  335. X.I deliver.
  336. X.TP
  337. X.B HEADER
  338. XThe name of the temporary file containing the message header.
  339. X.TP
  340. X.B BODY
  341. XThe name of the temporary file containing the message body.
  342. X.PP
  343. X.I deliver
  344. Xmonitors the standard output of delivery files for lines of two forms:
  345. Xeither "user" or "user:mailbox".  Those users whose names appear in the
  346. Xoutput of a delivery file will receive the message.  If a mailbox name
  347. Xappears after the user name, then that mailbox receives the message.  If a
  348. Xmailbox name is not specified, the user's default mailbox is used. (The
  349. Xdefault mailbox for a user is configuration-dependent.) If a mailbox is not
  350. Xan absolute pathname, it is interpreted relative to the home directory of
  351. Xthe named user.
  352. X.PP
  353. X.B NOTE 1:
  354. XWhen
  355. X.I deliver
  356. Xexecutes a delivery file, it expects that delivery file to explicitly name
  357. Xall users (and, optionally, mailboxes) which should receive the message.
  358. XIf a delivery file does not name any users in its output, then the message
  359. Xwill not be delivered to anyone whose mail delivery is controlled by that
  360. Xdelivery file.
  361. X.PP
  362. XTherefore, a user delivery file which contains only "exit" will keep the
  363. Xgiven user from receiving any mail.  A system delivery file which contains
  364. Xonly "exit" will cause
  365. X.B all
  366. Xmail to disappear.  So be careful!
  367. X.PP
  368. X.B NOTE 2:
  369. XIf
  370. X.I deliver
  371. Xis setuid root -- which it should be for normal operation -- then the system
  372. Xdelivery file is executed as root.  Be
  373. X.I very careful
  374. Xabout its permissions and its contents!  If you are not careful, it can
  375. Xeasily become a security hole.
  376. X.PP
  377. X.B NOTE 3:
  378. XAll user delivery files are executed in the context of the user in whose
  379. Xhome directory they reside.  A user's "context" includes the uid, gid, and
  380. Xhome directory as specified in /etc/passwd.
  381. X.PP
  382. X.B NOTE 4:
  383. XFor security reasons, if a user's home directory is writable to the world,
  384. X.I deliver
  385. Xwill ignore any deliver file that might be found there.
  386. X.PP
  387. X.B NOTE 5:
  388. XFor security reasons,
  389. X.I deliver
  390. Xrejects lines of the form "user:mailbox" when generated by a user delivery
  391. Xfile unless they are output by the given user's delivery file.  In other
  392. Xwords, no user can request writing a mailbox as another user.
  393. X.SH LOCKING
  394. XSeveral preprocessor labels may be defined during compilation to control
  395. Xthe method(s) used by
  396. X.I deliver
  397. Xto lock mailboxes.  These labels are:
  398. X.RS
  399. X.PP
  400. X.B ML_DOTLOCK
  401. XLock on exclusive creation of the mailbox name with ".lock"
  402. Xappended.  (Version 7 and early BSD mailers use this method.)
  403. X.PP
  404. X.B ML_DOTMLK
  405. XLock on exclusive creation of
  406. X.I /tmp/basename.mlk,
  407. Xwhere
  408. X.I basename
  409. Xis the last component of the mailbox pathname.  (Xenix mailers use this
  410. Xmethod.)
  411. X.PP
  412. X.B ML_LOCKF
  413. XExclusively lock mailbox with lockf().
  414. X.PP
  415. X.B ML_FCNTL
  416. XExclusively lock mailbox with fcntl().
  417. X.PP
  418. X.B ML_LOCKING
  419. XExclusively lock mailbox with locking().
  420. X.PP
  421. X.RE
  422. XOne or both of ML_DOTLOCK and ML_DOTMLK may be specified.  At most one of
  423. XML_LOCKF, ML_FCNTL or ML_LOCKING may be specified.
  424. X.SH FILES
  425. X/usr/local/lib/deliver.sys      system delivery file
  426. X.br
  427. X~user/.deliver                  user delivery file(s)
  428. X.br
  429. X/etc/systemid                   system name (Xenix only)
  430. X.SH SUPPORT
  431. XEnhancements, enhancement requests, trouble reports, etc.,
  432. Xshould be sent to
  433. X.sp
  434. X.ce
  435. Xbugs-deliver@ateng.UUCP.
  436. X.sp
  437. X.SH "SEE ALSO"
  438. X.IR uux (1),
  439. X.IR smail (8),
  440. X.IR mail (1)
  441. END_OF_FILE
  442. if test 8688 -ne `wc -c <'deliver.8'`; then
  443.     echo shar: \"'deliver.8'\" unpacked with wrong size!
  444. fi
  445. # end of 'deliver.8'
  446. fi
  447. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  448.   echo shar: Will not clobber existing file \"'Makefile'\"
  449. else
  450. echo shar: Extracting \"'Makefile'\" \(2960 characters\)
  451. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  452. X# $Header: Makefile,v 1.7 88/09/14 19:59:53 network Exp $
  453. X#
  454. X# Makefile for deliver
  455. X#
  456. X#  +----------------+
  457. X#  | Things to make |
  458. X#  +----------------+
  459. X#
  460. X#       deliver         Compile and link the deliver program.
  461. X#       install         Install deliver.  (You must be root to do this.)
  462. X#       lint            Run lint on all sources, creating lint.out.
  463. X#       shar            Create distribution sharchives.
  464. X#       clean           Clean up.
  465. X#       clobber         Remove everything that can be regenerated.
  466. X#
  467. X#  +---------------+
  468. X#  | Configuration |
  469. X#  +---------------+
  470. X#
  471. X# SHELL
  472. X#       I don't have to tell you...
  473. X#
  474. X# COPY
  475. X#       Your local copy program.  SCO Xenix users may want to change this
  476. X#       to "copy -m" which preserves file modification time.
  477. X#
  478. X# SHAR
  479. X#       Your local sharchive generator.
  480. X#
  481. X# CFLAGS
  482. X#       Compile-time flags to cc.
  483. X#       For BSD systems, include "-DBSD".
  484. X#       For USG (System III and System V) systems, include "-DUSG".
  485. X#
  486. X# LDFLAGS
  487. X#       Link-time flags to cc.  The -i flag creates pure (sharable) code.
  488. X#
  489. X# LIBS
  490. X#       Depending on your environment, you may or may not need to link
  491. X#       with "-lx".  SCO Xenix System V needs it; Altos Xenix doesn't.
  492. X#
  493. X# BIN
  494. X#       Target directory for installation; /usr/bin is recommended.
  495. X#       You may use /usr/local/bin (or whatever), but you must be sure
  496. X#       that the directory you choose is in your PATH during mail
  497. X#       transmission and delivery.
  498. X#
  499. X# DELSHAR
  500. X#       Basename of sharchives created by "make shar".
  501. X#
  502. X
  503. XSHELL = /bin/sh
  504. XCOPY =  cp
  505. XSHAR =  shar
  506. XCFLAGS = -O
  507. XLDFLAGS = -i
  508. XLIBS = -lx
  509. XBIN =   /usr/bin
  510. XDELSHAR =  deliver.sh
  511. X
  512. X#
  513. X# The files that make up the deliver distribution.
  514. X#
  515. X
  516. XDOCS =  README deliver.8
  517. XMF   =  Makefile
  518. X
  519. XHDRS =  config.h context.h deliver.h dest.h patchlevel.h misc.h
  520. X
  521. XSRC1 =  context.c copymsg.c debug.c dest.c dfile.c lock.c
  522. XSRC2 =  main.c mbox.c procs.c subs.c sysdep.c uucp.c
  523. XSRCS =  $(SRC1) $(SRC2)
  524. X
  525. XOBJS =  context.o copymsg.o debug.o dest.o dfile.o lock.o \
  526. X    main.o mbox.o procs.o subs.o sysdep.o uucp.o
  527. X
  528. Xall: deliver
  529. Xdeliver: $(OBJS)
  530. X    $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
  531. X$(OBJS): $(HDRS)
  532. X
  533. Xclean::
  534. X    rm -f $(OBJS)
  535. X
  536. X#
  537. X# This is a klugy way to determine if you are root or not.
  538. X# I'm open to suggestions!  (Remember that 'su' counts.)
  539. X#
  540. X
  541. Xinstall: deliver
  542. X    @if [ ! -w /etc ]; \
  543. X    then \
  544. X        echo ""; \
  545. X        echo "Sorry!  You must be root to install deliver."; \
  546. X        exit 1; \
  547. X    fi
  548. X    $(COPY) deliver $(BIN)/deliver
  549. X    chgrp root $(BIN)/deliver
  550. X    chown root $(BIN)/deliver
  551. X    chmod 4711 $(BIN)/deliver
  552. X
  553. Xclobber::
  554. X    rm -f deliver
  555. X
  556. X#
  557. X# Look for fuzz.
  558. X#
  559. X
  560. Xlint: lint.out
  561. Xlint.out: $(HDRS) $(SRCS)
  562. X    lint $(SRCS) -lc $(LIBS) >lint.out
  563. X
  564. Xclean::
  565. X    rm -f lint.out
  566. X
  567. X#
  568. X# Make distribution sharchives.
  569. X#
  570. X
  571. Xshar:   $(DELSHAR).01 $(DELSHAR).02 $(DELSHAR).03
  572. X$(DELSHAR).01: $(DOCS) $(MF) $(HDRS)
  573. X    $(SHAR) >$@ $(DOCS) $(MF) $(HDRS)
  574. X$(DELSHAR).02: $(SRC1)
  575. X    $(SHAR) >$@ $(SRC1)
  576. X$(DELSHAR).03: $(SRC2)
  577. X    $(SHAR) >$@ $(SRC2)
  578. X
  579. Xclobber::
  580. X    rm -f $(DELSHAR).??
  581. END_OF_FILE
  582. if test 2960 -ne `wc -c <'Makefile'`; then
  583.     echo shar: \"'Makefile'\" unpacked with wrong size!
  584. fi
  585. # end of 'Makefile'
  586. fi
  587. if test -f 'config.h' -a "${1}" != "-c" ; then 
  588.   echo shar: Will not clobber existing file \"'config.h'\"
  589. else
  590. echo shar: Extracting \"'config.h'\" \(4412 characters\)
  591. sed "s/^X//" >'config.h' <<'END_OF_FILE'
  592. X/* $Header: config.h,v 1.3 88/09/14 19:41:35 network Exp $
  593. X *
  594. X * Deliver configuration.
  595. X *
  596. X * $Log:    config.h,v $
  597. X * Revision 1.3  88/09/14  19:41:35  network
  598. X * Portability to System V and BSD.
  599. X * General fixup.
  600. X * 
  601. X * Revision 1.2  88/08/25  15:21:15  network
  602. X * Change default system delivery file to "/usr/local/lib/deliver.sys".
  603. X * Add ENV_SYSDEL and ENV_USERDEL for system and user delivery filenames.
  604. X * 
  605. X * Revision 1.1  88/06/06  09:37:27  chip
  606. X * Initial revision
  607. X * 
  608. X */
  609. X
  610. X/*----------------------------------------------------------------------
  611. X * Various kinds of mailbox locking.
  612. X * You may define one or both of ML_DOTLOCK and ML_DOTMLK.
  613. X * You may define no more than one of ML_FCNTL, ML_LOCKF and ML_LOCKING.
  614. X *
  615. X * File creation locking:
  616. X *     ML_DOTLOCK   create <mailbox>.lock       (most systems except BSD4.3)
  617. X *     ML_DOTMLK    create /tmp/<basename>.mlk  (Xenix)
  618. X *
  619. X * Kernel record locking:
  620. X *     ML_FCNTL     lock with fcntl(F_SETLKW)   (SVID systems only)
  621. X *     ML_LOCKF     lock with lockf(F_LOCK)     (SVID systems only)
  622. X *     ML_LOCKING   lock with locking(LK_LOCK)  (Xenix systems only)
  623. X */
  624. X
  625. X#ifdef M_XENIX
  626. X#define ML_DOTMLK
  627. X#define ML_LOCKING
  628. X#else
  629. X#define ML_DOTLOCK
  630. X#endif
  631. X
  632. X/*----------------------------------------------------------------------
  633. X * Maximum filename length.
  634. X * Note that this is for _filenames_, not _pathnames_.
  635. X * For AT&T file systems, the usual value is 14.
  636. X * For Berzerkley file systems, use something big like 255.
  637. X */
  638. X
  639. X#ifdef BSD
  640. X#define MAX_NAMESIZE    255
  641. X#else
  642. X#define MAX_NAMESIZE    14
  643. X#endif
  644. X
  645. X/*----------------------------------------------------------------------
  646. X * How to get the host name.
  647. X *
  648. X * HOSTFILE             file containing name    (Xenix)
  649. X * UNAME                uname()                 (System V)
  650. X * GETHOSTNAME          gethostname()           (BSD)
  651. X */
  652. X
  653. X#ifdef M_XENIX
  654. X#define HOSTFILE   "/etc/systemid"
  655. X#else
  656. X#ifdef USG
  657. X#define UNAME
  658. X#else
  659. X#ifdef BSD
  660. X#define GETHOSTNAME
  661. X#endif
  662. X#endif
  663. X#endif
  664. X
  665. X/*----------------------------------------------------------------------
  666. X * Are vprintf() and friends available?
  667. X * Is putenv() available?
  668. X */
  669. X
  670. X#ifndef BSD
  671. X#define HAS_VPRINTF
  672. X#define HAS_PUTENV
  673. X#endif
  674. X
  675. X/*----------------------------------------------------------------------
  676. X * Name of shell used to execute delivery files.
  677. X */
  678. X
  679. X#define SHELL   "/bin/sh"
  680. X
  681. X/*----------------------------------------------------------------------
  682. X * Standard mailbox location.
  683. X *
  684. X * Define either MAILBOX_NAME or MAILBOX_DIR.
  685. X * If MAILBOX_NAME is defined, then the default mailbox is a file with
  686. X * that name in the user's home directory.
  687. X * If MAILBOX_DIR is defined, then the default mailbox is a file in that
  688. X * directory with the same name as the user.
  689. X *
  690. X * Define MAILBOX_GROUP if all mailboxes must be owned by a specific group.
  691. X * (System V requires this feature.)  If MAILBOX_GROUP is not defined,
  692. X * mailboxes will have their groups set to the recipients' default group.
  693. X *
  694. X * Define MAILBOX_MODE to the file access modes for new mailboxes.
  695. X * (System V requires group write permissions, i.e. 0020.)
  696. X */
  697. X
  698. X#ifdef USG
  699. X/* #define MAILBOX_NAME   "mbox" */
  700. X#define MAILBOX_DIR     "/usr/mail"
  701. X#define MAILBOX_MODE    0660
  702. X#define MAILBOX_GROUP   "mail"
  703. X#else
  704. X/* #define MAILBOX_NAME   "mbox" */
  705. X#define MAILBOX_DIR     "/usr/spool/mail"
  706. X#define MAILBOX_MODE    0600
  707. X#endif
  708. X
  709. X/*----------------------------------------------------------------------
  710. X * Names of delivery files.
  711. X *
  712. X * SYS_DELIVER          system-wide delivery file
  713. X * USER_DELIVER         user delivery file (in user's home directory)
  714. X */
  715. X
  716. X#define SYS_DELIVER     "/usr/local/lib/deliver.sys"
  717. X#define USER_DELIVER    ".deliver"
  718. X
  719. X/*----------------------------------------------------------------------
  720. X * Environment variables passed to child processes.
  721. X * Variables marked with [#] are created only if they are specified
  722. X * as command line options.
  723. X */
  724. X
  725. X#define ENV_DFLAGS      "DELFLAGS"      /* Flags: [-[Avdt]]             */
  726. X#define ENV_SYSDEL      "SYSDELFILE"    /* System delivery file [#]     */
  727. X#define ENV_USERDEL     "USERDELFILE"   /* User delivery file [#]       */
  728. X
  729. X#define ENV_HOSTNAME    "HOSTNAME"      /* Name of this host            */
  730. X#define ENV_SENDER      "SENDER"        /* Message sender [#]           */
  731. X#define ENV_HEADER      "HEADER"        /* Message header file          */
  732. X#define ENV_BODY        "BODY"          /* Message body file            */
  733. END_OF_FILE
  734. if test 4412 -ne `wc -c <'config.h'`; then
  735.     echo shar: \"'config.h'\" unpacked with wrong size!
  736. fi
  737. # end of 'config.h'
  738. fi
  739. if test -f 'context.h' -a "${1}" != "-c" ; then 
  740.   echo shar: Will not clobber existing file \"'context.h'\"
  741. else
  742. echo shar: Extracting \"'context.h'\" \(423 characters\)
  743. sed "s/^X//" >'context.h' <<'END_OF_FILE'
  744. X/* $Header: context.h,v 1.1 88/06/06 09:37:40 chip Exp $
  745. X *
  746. X * User context, as found in /etc/passwd.
  747. X *
  748. X * $Log:    context.h,v $
  749. X * Revision 1.1  88/06/06  09:37:40  chip
  750. X * Initial revision
  751. X * 
  752. X */
  753. X
  754. X/*----------------------------------------------------------------------
  755. X * The context structure.
  756. X */
  757. X
  758. X#define CONTEXT struct context
  759. XCONTEXT {
  760. X    CONTEXT *next;
  761. X    int     uid;
  762. X    int     gid;
  763. X    char    *name;
  764. X    char    *home;
  765. X};
  766. END_OF_FILE
  767. if test 423 -ne `wc -c <'context.h'`; then
  768.     echo shar: \"'context.h'\" unpacked with wrong size!
  769. fi
  770. # end of 'context.h'
  771. fi
  772. if test -f 'deliver.h' -a "${1}" != "-c" ; then 
  773.   echo shar: Will not clobber existing file \"'deliver.h'\"
  774. else
  775. echo shar: Extracting \"'deliver.h'\" \(2690 characters\)
  776. sed "s/^X//" >'deliver.h' <<'END_OF_FILE'
  777. X/* $Header: deliver.h,v 1.3 88/09/14 19:41:50 network Exp $
  778. X *
  779. X * General pull-it-together include file.
  780. X *
  781. X * $Log:    deliver.h,v $
  782. X * Revision 1.3  88/09/14  19:41:50  network
  783. X * Portability to System V and BSD.
  784. X * General fixup.
  785. X * 
  786. X * Revision 1.2  88/08/30  16:13:03  network
  787. X * Add copystr().
  788. X * 
  789. X * Revision 1.1  88/06/06  09:36:49  chip
  790. X * Initial revision
  791. X * 
  792. X */
  793. X
  794. X#include <stdio.h>
  795. X#include <fcntl.h>
  796. X#include <ctype.h>
  797. X
  798. X#include "config.h"
  799. X#include "misc.h"
  800. X#include "context.h"
  801. X#include "dest.h"
  802. X
  803. X/*----------------------------------------------------------------------
  804. X * Global data
  805. X */
  806. X
  807. Xextern  int     verbose;        /* Print debugging messages?            */
  808. Xextern  int     dryrun;         /* Are we making a dry run?             */
  809. Xextern  int     printaddrs;     /* Address resolution only?             */
  810. Xextern  int     leavetemps;     /* Leave temp files for later perusal   */
  811. Xextern  int     boxdelivery;    /* Args are mailboxes, not addresses    */
  812. Xextern  char    *sender;        /* Who is sending this message?         */
  813. X
  814. Xextern  char    *progname;      /* Name this program was invoked under  */
  815. Xextern  char    *hostname;      /* Name of this host                    */
  816. X
  817. Xextern  char    *sys_deliver;   /* Systemwide delivery file             */
  818. Xextern  char    *user_deliver;  /* User delivery file                   */
  819. Xextern  char    *shell;         /* Shell used to run delivery files     */
  820. X
  821. Xextern  int     eff_uid;        /* Returned by geteuid()                */
  822. Xextern  int     eff_gid;        /* Returned by getegid()                */
  823. Xextern  int     real_uid;       /* Returned by getuid()                 */
  824. Xextern  int     real_gid;       /* Returned by getgid()                 */
  825. X
  826. Xextern  CONTEXT *eff_ct;        /* Context of effective uid             */
  827. Xextern  CONTEXT *real_ct;       /* Context of real uid                  */
  828. X
  829. X/* Temp file indices: */
  830. X#define T_HEADER 0      /* Temp file for message header         */
  831. X#define T_BODY   1      /* Temp file for message body           */
  832. X#define T_MAX    2      /* Number of temp files                 */
  833. X
  834. Xextern  char    *ttype[T_MAX];  /* Temp file types (for messages)       */
  835. Xextern  char    *tfile[T_MAX];  /* Temp file names                      */
  836. Xextern  int     tfd[T_MAX];     /* Temp file fd's                       */
  837. X
  838. X/*----------------------------------------------------------------------
  839. X * Global functions
  840. X */
  841. X
  842. Xchar    *basename();
  843. Xchar    *gethost();
  844. Xchar    *copystr();
  845. Xchar    *zalloc();
  846. Xchar    *srealloc();
  847. X
  848. XCONTEXT *name_context();
  849. XCONTEXT *uid_context();
  850. X
  851. XFILE    *ct_popenv();
  852. Xint     ct_pclose();
  853. X
  854. XDEST    *dest();
  855. XDEST    *first_dest();
  856. XDEST    *next_dest();
  857. END_OF_FILE
  858. if test 2690 -ne `wc -c <'deliver.h'`; then
  859.     echo shar: \"'deliver.h'\" unpacked with wrong size!
  860. fi
  861. # end of 'deliver.h'
  862. fi
  863. if test -f 'dest.h' -a "${1}" != "-c" ; then 
  864.   echo shar: Will not clobber existing file \"'dest.h'\"
  865. else
  866. echo shar: Extracting \"'dest.h'\" \(1636 characters\)
  867. sed "s/^X//" >'dest.h' <<'END_OF_FILE'
  868. X/* $Header: dest.h,v 1.1 88/06/06 09:37:48 chip Exp $
  869. X *
  870. X * Description of a mail destination and its state.
  871. X *
  872. X * $Log:    dest.h,v $
  873. X * Revision 1.1  88/06/06  09:37:48  chip
  874. X * Initial revision
  875. X * 
  876. X */
  877. X
  878. X/*----------------------------------------------------------------------
  879. X * Destination class.
  880. X */
  881. X
  882. Xtypedef enum {
  883. X    CL_USER,                /* User name, no mailbox                */
  884. X    CL_MBOX,                /* User name, with mailbox name         */
  885. X    CL_UUCP                 /* UUCP address (bang path)             */
  886. X} DCLASS;
  887. X
  888. X/*----------------------------------------------------------------------
  889. X * Destination state.
  890. X */
  891. X
  892. Xtypedef enum {
  893. X    ST_WORKING,             /* the "normal" state                   */
  894. X    ST_HOLD,                /* on hold during expansion             */
  895. X    ST_DONE,                /* all processing complete              */
  896. X    ST_ERROR                /* "something is horribly wrong"        */
  897. X} DSTATE;
  898. X
  899. X/*----------------------------------------------------------------------
  900. X * Structure describing a mail destination.
  901. X */
  902. X
  903. X#define DEST    struct dest
  904. XDEST {
  905. X    DEST    *next;          /* next destination in the chain        */
  906. X    DEST    *prev;          /* previous destination in the chain    */
  907. X    DCLASS  class;          /* destination class                    */
  908. X    DSTATE  state;          /* destination state                    */
  909. X    int     dfdone;         /* boolean -- delivery file was run     */
  910. X    char    *name;          /* context for delivery                 */
  911. X    char    *mailbox;       /* mailbox name or NULL for default     */
  912. X    char    *error;         /* error message (if state is ERROR)    */
  913. X};
  914. X
  915. END_OF_FILE
  916. if test 1636 -ne `wc -c <'dest.h'`; then
  917.     echo shar: \"'dest.h'\" unpacked with wrong size!
  918. fi
  919. # end of 'dest.h'
  920. fi
  921. if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  922.   echo shar: Will not clobber existing file \"'patchlevel.h'\"
  923. else
  924. echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
  925. sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
  926. X#define PATCHLEVEL 0
  927. END_OF_FILE
  928. if test 21 -ne `wc -c <'patchlevel.h'`; then
  929.     echo shar: \"'patchlevel.h'\" unpacked with wrong size!
  930. fi
  931. # end of 'patchlevel.h'
  932. fi
  933. if test -f 'misc.h' -a "${1}" != "-c" ; then 
  934.   echo shar: Will not clobber existing file \"'misc.h'\"
  935. else
  936. echo shar: Extracting \"'misc.h'\" \(1423 characters\)
  937. sed "s/^X//" >'misc.h' <<'END_OF_FILE'
  938. X/* $Header: misc.h,v 1.2 88/09/14 19:42:20 network Exp $
  939. X *
  940. X * Miscellaneous definitions.
  941. X *
  942. X * $Log:    misc.h,v $
  943. X * Revision 1.2  88/09/14  19:42:20  network
  944. X * Portability to System V and BSD.
  945. X * General fixup.
  946. X * 
  947. X * Revision 1.1  88/06/06  09:37:58  chip
  948. X * Initial revision
  949. X * 
  950. X */
  951. X
  952. X/*
  953. X * Non-portable include files
  954. X */
  955. X
  956. X#ifdef BSD
  957. X#include <strings.h>
  958. X#else
  959. X#include <string.h>
  960. X#include <memory.h>
  961. X#endif
  962. X
  963. X/*
  964. X * Constants
  965. X */
  966. X
  967. X#ifdef NULL
  968. X#undef NULL
  969. X#endif
  970. X#define NULL    0               /* The One True NULL */
  971. X
  972. X#define FALSE   0
  973. X#define TRUE    1
  974. X
  975. X/*
  976. X * Macros.
  977. X */
  978. X
  979. X/* Length parameter for fgets() on given buffer. */
  980. X
  981. X#define GETSIZE(buf)    (int) (sizeof(buf) - 1)
  982. X
  983. X/*
  984. X * Public data
  985. X */
  986. X
  987. Xextern  char    **environ;
  988. X
  989. X/*
  990. X * Library functions
  991. X */
  992. X
  993. Xextern  char    *ctime();
  994. Xextern  char    *getenv();
  995. Xextern  char    *malloc();
  996. Xextern  char    *realloc();
  997. Xextern  char    *mktemp();
  998. Xextern  int     putenv();
  999. Xextern  long    lseek();
  1000. Xextern  long    time();
  1001. Xextern  void    free();
  1002. X
  1003. X/*
  1004. X * Library differences
  1005. X */
  1006. X
  1007. X#ifdef BSD
  1008. X
  1009. Xextern  int     setlinebuf();
  1010. X
  1011. X#define strchr          index
  1012. X#define strrchr         rindex
  1013. X#define memcpy(d,s,n)   bcopy(s,d,n)
  1014. X#define Zero(d,n)       bzero(d,n)
  1015. X#define Linebuf(f)      setlinebuf(f)
  1016. X
  1017. X#else   /* not BSD */
  1018. X
  1019. Xextern  int     setvbuf();
  1020. X
  1021. X#define Zero(d,n)       memset(d,0,(int)(n))
  1022. X#define Linebuf(f)      setvbuf(f, _IOLBF, (char *)NULL, BUFSIZ)
  1023. X
  1024. X#endif  /* not BSD */
  1025. END_OF_FILE
  1026. if test 1423 -ne `wc -c <'misc.h'`; then
  1027.     echo shar: \"'misc.h'\" unpacked with wrong size!
  1028. fi
  1029. # end of 'misc.h'
  1030. fi
  1031. echo shar: End of shell archive.
  1032. exit 0
  1033.  
  1034.